<script>
$(document).ready(function(){
	$('#view_date').datepicker({ dateFormat: 'yy-mm-dd' });
	$('#expected_date').datepicker({ dateFormat: 'yy-mm-dd' });
	
})
$(function() {
	     var scntDiv = $('#p_scents');
        var i = $('#p_scents tr').size() + 1;
        
        $('.addScnt').live('click', function() {
                $('<tr id="dd'+ i +'"> <td style="border:none;"><input type="text" class="span3"  name="code[]"id="code'+i+'" onchange="get_product1(this.value,product_name'+i+');"/></td> <td style="border:none;"><input type="text"  class="span3" name="product_name[]"   id="product_name'+i+'" readonly /></td> <td style="border:none;"><input type="text" class="span3" name="quantity[]" id="quantity'+ i +'"  /></td> <td style="border:none;"><a href="#" class="addScnt">ADD</a>&nbsp;&nbsp;&nbsp;<a href="#"  id="'+i+'" class="remScnt">Remove</a></td></tr>').appendTo(scntDiv);
                i++;
                return false;
        });
		 $('.remScnt').live('click', function() { 
		//alert(i)
		    if( i > 2 ) {
                        
						$(this).parents('tr').remove();
                        i--;
                }
                return false;
        });
        
        
});
 
function get_product(code){
	$.post("<?= site_url('enquiry/enquiry/get_productName')?>",{ code:code }, function(msg){
		if(msg){
			$('#product_name').val(msg)
			}else{
				$('#product_name').val(""),
				alert('No Product Is Available!!')
				}
		
		})
	
	}
	
function get_product1(code,rate){
		var id="#"+$(rate).attr('id')
		$.post("<?= site_url('enquiry/enquiry/get_productName')?>",{ code:code }, function(msg){
		if(msg){
				$(id).val(msg);	

			}else{
				$(id).val(""),
				alert('No Product Is Available!!')
				}
		
		})
	
}	
 
</script>
<h2 style="background-color:#368EE0; color:white; font-size:20px; padding:5px;">Update Enquiry</h2>
<?php echo form_open(current_url());?>

<!--<div id="infoMessage"><?php echo $message;?></div>-->
<table align="center">
<tr><td><br>CUSTOMER</td><td>
            <?php 
	 	$bl[0] = "--Select Customer--";
	   		foreach($customers as $customer){
				$bl[$customer->id] = $customer->name;
			}
			echo form_dropdown('id_customer', $bl,$user->customer_id, 'class="chzn-select span12" data-placeholder="Choose a Customer" name="id_customer" id="id_customer" required style="width:220px;"');  ?>
	
<a href="<?=site_url('people/supplier/create_supplier/st')?>" ><i class="icon-edit"></i></a> 
</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>

<tr>
<td>ENQUIRY NO</td> <td><?php echo form_input($enquiry_no);?></td>
</tr>  
<tr>
<td>DATE</td><td><?php echo form_input($view_date);?></td>
</tr>
<tr>      
<td>EXPECTED DATE</td><td><?php echo form_input($expected_date);?>  </td>
</tr>
</table>
<hr>

<table width="100%" class="table table-bordered" >

  <tr class="info">
              <td><b>Item Code</b></td>
              <td><b>Product Name</b></td>
			  <td><b>Quantity</b></td>
			  <td><b>Option</b></td>
             </tr>
 <tbody id="p_scents">           
<?php foreach($product as $pro){?>
  <tr><label for="p_scnts">
    <td style="border:none;"><input type="text" class="span3" name='code[]' onblur="get_product(this.value);" id="code"   value="<?= $pro->code ?>"/></td>
    <td style="border:none;"><input type="text" class="span3"  id="product_name"   name='product_name[]'  value="<?= $pro->name ?>"readonly/>
	<input type="hidden"   id="hid_rate"/></td>
    <td style="border:none;"><input type="text" class="span3" id="quantity" name='quantity[]' value="<?= $pro->quantity ?>"/></td>
  
<td style="border:none;"><a href="#" class="addScnt">ADD PRODUCT</a></td>
 </label> </tr>
 <?php }?>
  </tbody>
</table>  
<p align="right"><?php echo form_submit('submit', 'Update', 'class="btn btn-inverse"');?></p>
</form>
<!--<?php echo form_close();?>-->
